package com.store.pet.petstore.activity;

import android.os.Bundle;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.widget.TextView;

import com.gyf.barlibrary.ImmersionBar;
import com.store.pet.petstore.R;
import com.store.pet.petstore.bean.OrderBean;

import butterknife.BindView;

public class OrderDetailActivity extends BaseActivity {

    @BindView(R.id.my_status)
    View myStatus;
    @BindView(R.id.title)
    TextView title;
    @BindView(R.id.toolbar)
    Toolbar toolbar;
    @BindView(R.id.status)
    TextView status;
    @BindView(R.id.buyer_name)
    TextView buyerName;
    @BindView(R.id.buyer_phone)
    TextView buyerPhone;
    @BindView(R.id.buyer_address)
    TextView buyerAddress;
    @BindView(R.id.seller_name)
    TextView sellerName;
    @BindView(R.id.pet_name)
    TextView petName;
    @BindView(R.id.price)
    TextView price;
    @BindView(R.id.order_id)
    TextView orderId;
    @BindView(R.id.buy_time)
    TextView buyTime;
    @BindView(R.id.arrive)
    TextView arrive;

    private OrderBean.ContentBean.OrderListBean data;  //订单数据

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    @Override
    public int getLayoutID() {
        return R.layout.activity_order_detail;
    }

    @Override
    public void init(Bundle savedInstanceState) {
        //沉浸式标题栏
        ImmersionBar.with(this).statusBarDarkFont(true).init();
        takeLinearStatusBar(myStatus);
        setSupportActionBar(toolbar);
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
        toolbar.setNavigationIcon(R.drawable.back);  //设置左上角图标
        toolbar.setNavigationOnClickListener(view -> finish());  //退出
    }

    @Override
    public void loadData() {
        if (getIntent().getSerializableExtra("order") != null) {
            data = (OrderBean.ContentBean.OrderListBean) getIntent().getSerializableExtra("order");
            int s = data.getStatus();
            switch (s) {
                case 1:
                    status.setText("买家已下单");
                    break;
                case 2:
                    arrive.setVisibility(View.VISIBLE);
                    status.setText("卖家已发货");
                    break;
                case 3:
                    status.setText("买家已付款");
                    break;
            }
            buyerName.setText(data.getBuyername());
            buyerPhone.setText(data.getBuyerphone());
            buyerAddress.setText(data.getAddress());
            sellerName.setText(data.getSellername());
            petName.setText("宠物名：" + data.getPetname());
            price.setText("总价格：" + data.getPrice());
            orderId.setText("订单编号：" + data.getId());
            buyTime.setText("下单时间：" + data.getCtime().replaceAll("T", " "));
        }
    }
}
